<!DOCTYPE html>
<html lang="en">
<head>
    <title>登录页面</title>
    <link href="/css/style.css" rel='stylesheet' type='text/css'/>
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="keywords"
          content="Alley Signup & Signin Form Tab Form,Login Forms,Sign up Forms,Registration Forms,News letter Forms,Elements"
          ./>
    <script type="application/x-javascript"> addEventListener("load", function () {
        setTimeout(hideURLbar, 0);
    }, false);

    function hideURLbar() {
        window.scrollTo(0, 1);
    } </script>
    </script>
</head>
<body>
<h1> 会员登录 </h1>

<div class="main-content">
    <div class="sap_tabs">
        <div id="horizontalTab" style="display: block; width: 100%; margin: 0;">
            <div class="facts">
                <div class="register">
                    <label>
                        <input placeholder="用户名" type="text" name="username" id="uname" required="">
                    </label>
                    <label>
                        <input placeholder="密码" type="password" name="password" id="pwd" required="">
                    </label>
                    <div class="sign-up">
                        <input type="button" value="登录" id="loginBtn"/>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/jquery.min.js"></script>
<script src="/js/lay-module/common/common.js"></script>
<script src="/js/easyResponsiveTabs.js" type="text/javascript"></script>
<script src="/js/lay-config.js" charset="utf-8"></script>
<script type="text/javascript">
    layui.use(['layer'], function () {
        let $ = layui.jquery,
            layer = layui.layer;

        let successMsg = function (msg) {
            layer.msg(msg, {
                icon: 1,
                time: 1200
            });
        }

        let errorMsg = function (msg) {
            layer.msg(msg, {
                icon: 2,
                time: 2000
            });
        }

        $("#loginBtn").on("click", function () {
            let uname = $("#uname").val();
            let pwd = $("#pwd").val();
            if (uname === null || uname === '') {
                errorMsg("用户名不能为空！");
            } else if (pwd === null || pwd === '') {
                errorMsg("密码不能为空！");
            } else {
                $.post("/login", {username: uname, password: pwd}, function (vo) {
                    if (vo.code === 0){
                        window.top.location.href = "/";
                    } else {
                        window.top.location.href = "/login";
                    }
                });
            }

        });
    })

</script>

</body>
</html>